package com.jboltai.capability.vdb.types.elasticsearch;

import cn.hutool.core.util.StrUtil;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem;
import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse;
import co.elastic.clients.elasticsearch.indices.DeleteIndexRequest;
import co.elastic.clients.elasticsearch.indices.DeleteIndexResponse;
import co.elastic.clients.elasticsearch.indices.ExistsRequest;
import co.elastic.clients.elasticsearch.sql.TranslateRequest;
import co.elastic.clients.elasticsearch.sql.TranslateResponse;
import co.elastic.clients.transport.endpoints.BooleanResponse;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.util.RawValue;
import com.jboltai.capability.embedding.JBoltEmbedding;
import com.jboltai.capability.vdb.JBoltVDB;
import com.jboltai.capability.vdb.VDBOptResult;
import com.jboltai.capability.vdb.collection.VDBCollection;
import com.jboltai.capability.vdb.collection.field.VDBField;
import com.jboltai.capability.vdb.collection.field.VDBFieldType;
import com.jboltai.capability.vdb.doc.VDBDoc;
import com.jboltai.capability.vdb.search.VDBConditions;
import com.jboltai.event.embedding.EmbeddingEvent;
import com.jboltai.resource.vdb.VDBResource;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class JBoltElasticSearchVDB extends JBoltVDB {
    public JBoltElasticSearchVDB(VDBResource resource) {
        super(resource);
    }

    public Client getClient() {
        ElasticSearchVDBResource resource = (ElasticSearchVDBResource) getResource();
        return resource.getClient();
    }

    @Override
    public VDBOptResult<Boolean> createCollection(VDBCollection collection) {
        if (resource.getEmbeddingModel() == null) {
            throw new RuntimeException("向量数据库[" + resource.getId() + "]未指定Embedding模型");
        }
        Client client = getClient();

        // 表名
        String collectionName = collection.getName();

        // 属性
        String json = propertyToJSON(collection);

        try {
            StringReader reader = new StringReader(json);
            CreateIndexResponse response = client.getEsClient().indices().create(c -> c.index(collectionName).withJson(reader));
            return successData(response.acknowledged());
        } catch (Exception e) {
            String message = e.getMessage();
            if (message.contains("[resource_already_exists_exception]")) {
                VDBOptResult<Boolean> fail = fail();
                fail.setMsg("INDEX已存在");
                return fail;
            }
            e.printStackTrace();
            return error(e);
        }
    }

    public VDBOptResult<Boolean> createCollectionNoEmbedding(String collectionName, List<VDBField> fieldList) {
        // 属性
        String json = propertyToJSONNoEmbedding(fieldList);

        try {
            StringReader reader = new StringReader(json);
            CreateIndexResponse response = getClient().getEsClient().indices().create(c -> c.index(collectionName).withJson(reader));
            return successData(response.acknowledged());
        } catch (Exception e) {
            String message = e.getMessage();
            if (message.contains("[resource_already_exists_exception]")) {
                VDBOptResult<Boolean> fail = fail();
                fail.setMsg("INDEX已存在");
                return fail;
            }
            e.printStackTrace();
            return error(e);
        }
    }

    private String propertyToJSONNoEmbedding(List<VDBField> fieldList) {
        JSONObject properties = new JSONObject();

        for (VDBField field : fieldList) {
            VDBFieldType vdbFieldType = field.getVdbFieldType();
            JSONObject jsonObject = new JSONObject();
            if (field.isPrimaryKey()) {
                jsonObject.put("type", "keyword");
            } else if (field.getName().equals(VDBField.DOC_FIELD_NAME)) {
                jsonObject.put("type", "text");
            } else {
                if (vdbFieldType == VDBFieldType.STRING) {
                    jsonObject.put("type", "keyword");
                } else if (vdbFieldType == VDBFieldType.NUMBER32) {
                    jsonObject.put("type", "integer");
                } else if (vdbFieldType == VDBFieldType.NUMBER64) {
                    jsonObject.put("type", "long");
                }
            }
            properties.put(field.getName(), jsonObject);
        }

        JSONObject mappings = new JSONObject();
        mappings.put("properties", properties);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("mappings", mappings);

        return jsonObject.toJSONString();
    }

    private String propertyToJSON(VDBCollection collection) {
        JSONObject properties = new JSONObject();

        for (VDBField field : collection.getFields()) {
            VDBFieldType vdbFieldType = field.getVdbFieldType();
            JSONObject jsonObject = new JSONObject();
            if (field.isPrimaryKey()) {
                jsonObject.put("type", "keyword");
            } else if (field.getName().equals(VDBField.DOC_FIELD_NAME)) {
                jsonObject.put("type", "text");
            } else {
                if (vdbFieldType == VDBFieldType.STRING) {
                    jsonObject.put("type", "keyword");
                } else if (vdbFieldType == VDBFieldType.NUMBER32) {
                    jsonObject.put("type", "integer");
                } else if (vdbFieldType == VDBFieldType.NUMBER64) {
                    jsonObject.put("type", "long");
                } else if (vdbFieldType == VDBFieldType.VECTOR) {
                    jsonObject.put("type", "dense_vector");
                    jsonObject.put("dims", resource.getEmbeddingModel().getDimension());
                }
            }
            properties.put(field.getName(), jsonObject);
        }

        JSONObject mappings = new JSONObject();
        mappings.put("properties", properties);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("mappings", mappings);

        return jsonObject.toJSONString();
    }

    @Override
    public VDBOptResult<Boolean> dropCollection(String tableName) {
        Client client = getClient();
        try {
            DeleteIndexRequest request = DeleteIndexRequest.of(o -> o.index(tableName));
            DeleteIndexResponse response = client.getEsClient().indices().delete(request);
            return successData(response.acknowledged());
        } catch (Exception e) {
            String message = e.getMessage();
            if (message.contains("[index_not_found_exception]")) {
                return success();
            }
            e.printStackTrace();
            return error(e);
        }
    }

    @Override
    public VDBOptResult<Boolean> checkCollectionExist(String tableName) {
        Client client = getClient();
        try {
            ExistsRequest request = ExistsRequest.of(o -> o.index(tableName));
            BooleanResponse response = client.getEsClient().indices().exists(request);
            return successData(response.value());
        } catch (Exception e) {
            e.printStackTrace();
            return error(e);
        }
    }

    @Override
    public VDBOptResult<Boolean> truncateCollection(String tableName) {
        Client client = getClient();
        try {
            DeleteByQueryRequest request = DeleteByQueryRequest.of(o -> o.index(tableName));
            DeleteByQueryResponse response = client.getEsClient().deleteByQuery(request);
            return successData(response.total() > 0);
        } catch (Exception e) {
            e.printStackTrace();
            return error(e);
        }
    }

    @Override
    public VDBOptResult<Integer> insert(String tableName, VDBDoc... docs) {
        try {
            BulkRequest.Builder request = new BulkRequest.Builder();
            for (VDBDoc doc : docs) {
                String json = VDBDocToJSON(doc);
                request.operations(o -> o.create(c -> c.index(tableName).document(new RawValue(json))));
            }
            BulkResponse response = getClient().getEsClient().bulk(request.build());
            if (response.errors()) {
                List<BulkResponseItem> itemList = response.items();
                for (BulkResponseItem item : itemList) {
                    deleteById(tableName, item.id());
                }
                return failData(0);
            }
            return successData(docs.length);
        } catch (Exception e) {
            e.printStackTrace();
            return error(e);
        }
    }

    public VDBOptResult<Integer> insertNoEmbedding(String tableName, VDBDoc... docs) {
        try {
            BulkRequest.Builder request = new BulkRequest.Builder();
            for (VDBDoc doc : docs) {
                String json = VDBDocToJSONNoEmbedding(doc);
                request.operations(o -> o.create(c -> c.index(tableName).document(new RawValue(json))));
            }
            BulkResponse response = getClient().getEsClient().bulk(request.build());
            if (response.errors()) {
                List<BulkResponseItem> itemList = response.items();
                for (BulkResponseItem item : itemList) {
                    deleteById(tableName, item.id());
                }
                return failData(0);
            }
            return successData(docs.length);
        } catch (Exception e) {
            e.printStackTrace();
            return error(e);
        }
    }

    private String VDBDocToJSON(VDBDoc doc) {
        JSONObject jsonObject = new JSONObject();

        if (StrUtil.isNotBlank(doc.getId())) {
            jsonObject.put(VDBField.ID_FIELD_NAME, doc.getId());
        }

        if (StrUtil.isNotBlank(doc.getDoc())) {
            String docStr = doc.getDoc();
            List<Float> vector = embedding(docStr);
            jsonObject.put(VDBField.DOC_FIELD_NAME, doc.getDoc());
            jsonObject.put(VDBField.VECTOR_FIELD_NAME, vector);
        }

        Map<String, Object> fieldMap = doc.getFieldValues();
        for (String key : fieldMap.keySet()) {
            jsonObject.put(key, fieldMap.get(key));
        }
        return jsonObject.toJSONString();
    }

    private String VDBDocToJSONNoEmbedding(VDBDoc doc) {
        JSONObject jsonObject = new JSONObject();

        if (StrUtil.isNotBlank(doc.getId())) {
            jsonObject.put(VDBField.ID_FIELD_NAME, doc.getId());
        }

        if (StrUtil.isNotBlank(doc.getDoc())) {
            jsonObject.put(VDBField.DOC_FIELD_NAME, doc.getDoc());
        }

        Map<String, Object> fieldMap = doc.getFieldValues();
        if (fieldMap != null) {
            for (String key : fieldMap.keySet()) {
                jsonObject.put(key, fieldMap.get(key));
            }
        }
        return jsonObject.toJSONString();
    }

    private List<Float> embedding(String doc) {
        EmbeddingEvent event = JBoltEmbedding.embedding(resource.getEmbeddingModel(), doc);
        event.onSuccess((e, r) -> {
            event.setAttr("result", r.get(0));
        }).onFail((e, err) -> {
            Throwable t = err.getException();
            throw new RuntimeException(t);
        });
        event.publish().await();
        List<Double> vector = event.getAttr("result");
        return vector.stream().map(Double::floatValue).collect(Collectors.toList());
    }

    public VDBOptResult<List<VDBDoc>> fullTextSearch(String collectionName, VDBConditions conditions) {
        if (collectionName == null) {
            throw new RuntimeException("未指定collectionName");
        }

        Client client = getClient();

        try {
            List<String> matchTextList = conditions.getMatchText();
            if (matchTextList != null && matchTextList.size() > 1) {
                throw new RuntimeException("仅支持单条全文检索");
            }
            if (conditions.getLimit() == null) {
                conditions.limit(10);
            }

            // 拼接SQL
            String SQL = SQLBuilder.select(collectionName, conditions);
            // SQL to DSL
            JSONObject DSL = translate(SQL);
            DSL.remove("_source");
            DSL.remove("sort");
            DSL.remove("fields");
            if (conditions.getExtra() != null) {
                DSL.putAll(conditions.getExtra());
            }


            StringReader reader = new StringReader(DSL.toJSONString());
            SearchRequest.Builder builder = new SearchRequest.Builder();
            builder.index(collectionName).withJson(reader);

            SearchResponse<JSONObject> searchResponse = client.getEsClient().search(builder.build(), JSONObject.class);

            List<VDBDoc> vdbDocList = new ArrayList<>();
            List<Hit<JSONObject>> hitList = searchResponse.hits().hits();
            for (Hit<JSONObject> hit : hitList) {
                Double score = hit.score();
                JSONObject source = hit.source();

                VDBDoc doc = new VDBDoc();
                doc.setScore(score);
                for (String columnName : source.keySet()) {
                    String columnValue = source.getString(columnName);
                    switch (columnName) {
                        case VDBField.ID_FIELD_NAME:
                            doc.setId(columnValue);
                            continue;
                        case VDBField.DOC_FIELD_NAME:
                            doc.setDoc(columnValue);
                            continue;
                        default:
                            doc.setField(columnName, columnValue);
                            continue;
                    }
                }

                //处理高亮
                Map<String, List<String>> highlight = hit.highlight();
                if (highlight != null) {
                    if (highlight.size() == 1 && highlight.containsKey(VDBField.DOC_FIELD_NAME)) {
                        doc.setField("_highlight", highlight.get(VDBField.DOC_FIELD_NAME));
                    }
                }

                vdbDocList.add(doc);
            }
            return successData(vdbDocList);
        } catch (Exception e) {
            e.printStackTrace();
            return error(e);
        }
    }

    @Override
    public VDBOptResult<List<VDBDoc>> search(String tableName, VDBConditions conditions) {
        if (tableName == null) {
            throw new RuntimeException("未指定集合");
        }

        Client client = getClient();

        try {
            String matchText = "";
            List<Float> vectorList = null;
            List<String> matchTextList = conditions.getMatchText();
            if (matchTextList != null && matchTextList.size() > 1) {
                throw new RuntimeException("仅支持单条向量检索");
            } else if (matchTextList != null && matchTextList.size() == 1) {
                matchText = matchTextList.get(0);
                vectorList = embedding(matchTextList.get(0));
            }

            Integer limit = conditions.getLimit() == null ? 3 : conditions.getLimit();
            Integer k = limit;
            Integer numCandidates = limit;
            Integer windowSize = limit;
            Integer rankConstant = limit;

            // 拼接SQL
            String sql = SQLBuilder.select(tableName, conditions);
            // SQL转DSL
            JSONObject sql2dslJO = translate(sql);

//            JSONObject filterJO = new JSONObject();
//            JSONObject boolJO = new JSONObject();
//            JSONObject matchJO = new JSONObject();
//            JSONArray mustJA = new JSONArray();
//            JSONObject docJO = new JSONObject();
//
//            filterJO.put("bool", boolJO);
//            boolJO.put("must", mustJA);
//
//            matchJO.put("match", docJO);
//            docJO.put(VDBField.DOC_FIELD_NAME, matchText);
//
//            JSONObject queryJO = sql2dslJO.getJSONObject("query");
//            if(queryJO != null){
//                for (String key : queryJO.keySet()) {
//                    JSONObject selectCond = new JSONObject();
//                    selectCond.put(key, queryJO.get(key));
//                    mustJA.add(selectCond);
//                }
//                mustJA.add(matchJO);
//            }
            JSONObject queryJO = queryJO(VDBField.DOC_FIELD_NAME, matchText);

            JSONObject filterJO = new JSONObject();

            JSONObject dslJO = new JSONObject();
            dslJO.put("query", queryJO);
            dslJO.put("knn", knnJO(VDBField.VECTOR_FIELD_NAME, vectorList, null, k, numCandidates));
            dslJO.put("rank", rankJO(windowSize, rankConstant));

            System.out.println(dslJO.toJSONString());

            StringReader reader = new StringReader(dslJO.toJSONString());
            SearchRequest.Builder builder = new SearchRequest.Builder();
            builder.index(tableName).withJson(reader);

            SearchResponse<JSONObject> searchResponse = client.getEsClient().search(builder.build(), JSONObject.class);

            List<VDBDoc> vdbDocList = new ArrayList<>();
            List<Hit<JSONObject>> hitList = searchResponse.hits().hits();
            for (Hit<JSONObject> hit : hitList) {
                JSONObject source = hit.source();

                VDBDoc doc = new VDBDoc();
                for (String columnName : source.keySet()) {
                    switch (columnName) {
                        case VDBField.ID_FIELD_NAME:
                            doc.setId(source.getString(columnName));
                            continue;
                        case VDBField.DOC_FIELD_NAME:
                            doc.setDoc(source.getString(columnName));
                            continue;
                        case VDBField.VECTOR_FIELD_NAME:
                            doc.setVector(source.getObject(columnName, List.class));
                            continue;
                        default:
                            doc.setField(columnName, source.getString(columnName));
                            continue;
                    }
                }
                doc.setScore(hit.score());
                vdbDocList.add(doc);
            }
            return successData(vdbDocList);
        } catch (Exception e) {
            e.printStackTrace();
            return error(e);
        }
    }

    private JSONObject queryJO(String matchField, String matchText) {
        JSONObject queryJO = new JSONObject();
        JSONObject boolJO = new JSONObject();
        JSONObject filterJO = new JSONObject();
        JSONObject matchJO = new JSONObject();

        queryJO.put("match", matchJO);
//        boolJO.put("filter", filterJO);
        matchJO.put(matchField, matchText);
        return queryJO;
    }

    private JSONObject knnJO(String field, List<Float> vectorList, JSONObject filterJO, Integer k, Integer numCandidates) {
        if (k == null || k < 1) {
            k = 50;
        }
        if (numCandidates == null || numCandidates < 1) {
            numCandidates = 100;
        }

        JSONObject knnJO = new JSONObject();
        knnJO.put("field", field);
        knnJO.put("query_vector", vectorList);
        if (filterJO != null) {
            knnJO.put("filter", filterJO);
        }
        knnJO.put("k", k);
        knnJO.put("num_candidates", numCandidates);

        return knnJO;
    }

    private JSONObject rankJO(Integer windowSize, Integer rankConstant) {
        if (windowSize == null || windowSize < 1) {
            windowSize = 100;
        }
        if (rankConstant == null || rankConstant < 1) {
            rankConstant = 60;
        }

        JSONObject rankJO = new JSONObject();
        JSONObject rrfJO = new JSONObject();

        rankJO.put("rrf", rrfJO);

        rrfJO.put("window_size", windowSize);
        rrfJO.put("rank_constant", rankConstant);

        return rankJO;
    }

//    @Override
//    public VDBOptResult<List<VDBDoc>> search(String tableName, VDBConditions conditions) {
//        if (tableName == null) {
//            throw new RuntimeException("未指定tableName");
//        }
//
//        Client client = getClient();
//
//        try {
//            String matchText = "";
//
//            List<Double> vectorList = null;
//
//            List<String> matchTextList = conditions.getMatchText();
//            if (matchTextList != null && matchTextList.size() > 1) {
//                throw new RuntimeException("仅支持单条向量检索");
//            } else if (matchTextList != null && matchTextList.size() == 1) {
//                matchText = matchTextList.get(0);
//                vectorList = embeddingDoc(matchTextList.get(0));
//            }
//
//            String question = matchText;
//
//            Float textBoost = conditions.getTextRate() == null ? 0.5F : conditions.getTextRate();
//            Float vectorBoost = conditions.getVectorRate() == null ? 0.5F : conditions.getVectorRate();
//
//            List<Float> vectorListFloat = vectorList.stream().map(Double::floatValue).collect(Collectors.toList());
//
//            Long limit = conditions.getLimit() == null ? 5L : conditions.getLimit().longValue();
//
//            Long k = limit;
//            Long numCandidates = k;
//
//            // 拼接SQL
//            String sql = SQLBuilder.select(tableName, conditions);
//            // SQL转DSL
//            JSONObject dsl = translate(sql);
//
//            JSONObject knnJO = new JSONObject();
//            knnJO.put("field", VDBField.VECTOR_FIELD_NAME);
//            knnJO.put("query_vector", vectorListFloat);
//            knnJO.put("k", k);
//            knnJO.put("num_candidates", numCandidates);
//
//            JSONObject filterJO = new JSONObject();
//            JSONObject boolJO = new JSONObject();
//            JSONObject matchJO = new JSONObject();
//            JSONArray mustJA = new JSONArray();
//            JSONObject docJO = new JSONObject();
//
//            filterJO.put("bool", boolJO);
//            boolJO.put("must", mustJA);
//
//            matchJO.put("match", docJO);
//            docJO.put(VDBField.DOC_FIELD_NAME, question);
//
//            JSONObject query = dsl.getJSONObject("query");
//            for (String key : query.keySet()) {
//                JSONObject selectCond = new JSONObject();
//                selectCond.put(key, query.get(key));
//                mustJA.add(selectCond);
//            }
//            mustJA.add(matchJO);
//
//            knnJO.put("filter", filterJO);
//
//            JSONObject a = new JSONObject();
//            a.put("size", limit);
//            a.put("knn", knnJO);
//
//            StringReader reader = new StringReader(a.toJSONString());
//            SearchRequest.Builder builder = new SearchRequest.Builder();
//            builder.index(tableName).withJson(reader);
//
//            SearchResponse<JSONObject> searchResponse = client.getEsClient().search(builder.build(), JSONObject.class);
//
//            List<VDBDoc> vdbDocList = new ArrayList<>();
//            List<Hit<JSONObject>> hitList = searchResponse.hits().hits();
//            for (Hit<JSONObject> hit : hitList) {
//                JSONObject source = hit.source();
//
//                VDBDoc doc = new VDBDoc();
//                for (String columnName : source.keySet()) {
//                    switch (columnName) {
//                        case VDBField.ID_FIELD_NAME:
//                            doc.setId(source.getString(columnName));
//                            continue;
//                        case VDBField.DOC_FIELD_NAME:
//                            doc.setDoc(source.getString(columnName));
//                            continue;
//                        case VDBField.VECTOR_FIELD_NAME:
//                            doc.setVector(source.getObject(columnName, List.class));
//                            continue;
//                        default:
//                            doc.setField(columnName, source.getString(columnName));
//                            continue;
//                    }
//                }
//                doc.setScore(hit.score());
//                vdbDocList.add(doc);
//            }
//            return successData(vdbDocList);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return error(e);
//        }
//    }

    @Override
    public VDBOptResult<Boolean> deleteById(String collectionName, String id) {
        return delete(collectionName, new VDBConditions().eq("id", id));
    }

    @Override
    public VDBOptResult<Boolean> delete(String tableName, VDBConditions conditions) {
        if (tableName == null) {
            throw new RuntimeException("未指定tableName");
        }
        Client client = getClient();
        try {
            // 拼接SQL
            String sql = SQLBuilder.select(tableName, conditions);
            // SQL转DSL
            JSONObject dsl = translate(sql);
            // 删除不必要的字段
            dsl.remove("size");
            dsl.remove("_source");
            dsl.remove("sort");
            dsl.remove("fields");
            StringReader reader = new StringReader(dsl.toJSONString());
            DeleteByQueryRequest request = DeleteByQueryRequest.of(o -> o.index(tableName).withJson(reader));
            DeleteByQueryResponse response = client.getEsClient().deleteByQuery(request);
            return successData(response.total() >= 0);
        } catch (Exception e) {
            e.printStackTrace();
            return error(e);
        }
    }

    @Override
    public VDBOptResult<Integer> update(String tableName, VDBDoc doc, VDBConditions conditions) {
        throw new RuntimeException("ES暂不支持");
    }

    @Override
    public VDBOptResult<List<VDBCollection>> listCollections() {
        throw new RuntimeException("ES暂不支持");
    }

    public JSONObject translate(String sql) {
        Client client = getClient();
        try {
            TranslateRequest request = TranslateRequest.of(o -> o.query(sql));
            TranslateResponse response = client.getEsClient().sql().translate(request);
            String json = response.toString().replace("TranslateResponse: ", "");
            return JSONObject.parseObject(json);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public Query SQL2Query(String sql) {
        Client client = getClient();
        try {
            TranslateRequest request = TranslateRequest.of(o -> o.query(sql));
            TranslateResponse response = client.getEsClient().sql().translate(request);
            return response.query();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private VDBOptResult<Boolean> success() {
        return new VDBOptResult<>(true, true);
    }

    private VDBOptResult<Boolean> fail() {
        return new VDBOptResult<>(false, false);
    }

    private <T> VDBOptResult<T> successData(T data) {
        return new VDBOptResult<>(true, data);
    }

    private <T> VDBOptResult<T> failData(T data) {
        return new VDBOptResult<>(false, data);
    }

    private <T> VDBOptResult<T> resultData(boolean success, T data) {
        return new VDBOptResult<>(success, data);
    }

    private VDBOptResult error(Throwable e) {
        return new VDBOptResult(e.getMessage(), e);
    }

    private VDBOptResult error(Throwable e, String message) {
        return new VDBOptResult(message, e);
    }

    @Override
    public VDBOptResult<Boolean> checkDatabaseExist(String database) {
        throw new RuntimeException("ES暂不支持");
    }

    @Override
    public VDBOptResult<Void> createDatabase(String database) {
        throw new RuntimeException("ES暂不支持");
    }

    @Override
    public VDBOptResult<Boolean> dropDatabase(String database) {
        throw new RuntimeException("ES暂不支持");
    }
}
